import os, zipfile


def listdir(folder):
    for folderName, subfolders, filenames in os.walk(folder):
        print('the current folder is :' + folderName)
        for subfolder in subfolders:
            print('subfolder of ' + folderName + ":" + subfolder)
        for filename in filenames:
            print('FILE INSIDE ' + folderName + ': ' + filename)

        print(' ')


def unZipFile(fileName):
    if os.path.exists(fileName):
        print(f"The file '{fileName}' exists.")
        myzip = zipfile.ZipFile(fileName)
        filelist = myzip.namelist()
        for file in filelist:
            print(file)
        code_info = myzip.getinfo("autotask/reg/regExpressionTest.py")
        print(code_info.file_size)
        print(code_info.compress_size)
        print('Compressed file is %sx smaller!' % (round(code_info.file_size / code_info.compress_size, 2)))
        myzip.close()


def unzip(zipFileName, unZipFile, unzipFolder):
    zip_ref = zipfile.ZipFile(zipFileName,'r')
    zip_ref.extract(unZipFile,unzipFolder)


# listdir("F:\\entertainment")
# unZipFile("F:\github\workspace\pythonLearning\\pyproject.zip")
unzip('F:\github\workspace\pythonLearning\pyproject.zip','autotask/reg/regExpressionTest.py','F:\\github\\test')
